#include"stdio.h"   
#include"stdlib.h"   
#include"string.h"   
#include"sys/socket.h"   
#include"netinet/in.h"   
#include"arpa/inet.h"   
#include"netdb.h"   
#include"errno.h"   
#include"fcntl.h"   
   
int main(int argc, char *argv[])    
{   
    int sockfd;   
    char buffer[4096];   
    struct sockaddr_in server_addr;   
    int nbytes,sendlen;   
    char *host = "127.0.0.1";
    int port = 9457;

    char* msg = "qihoo 360is a qihu360 qihoo360 立场力量什么立即春夏秋冬，立秋了，";

    /* 客户程序开始建立sockfd描述符 */   
    if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)   
    {   
        fprintf(stderr,"Socket Error:%s\a\n",strerror(errno));   
        exit(1);   
    }   
    /* 客户程序填充服务端的资料 */   
    bzero(&server_addr,sizeof(server_addr));   
    server_addr.sin_family = AF_INET;   
    server_addr.sin_port = htons(port);   
    server_addr.sin_addr.s_addr = inet_addr(host);

    /* 客户程序发起连接请求 */   
    if(connect(sockfd,(struct sockaddr *)(&server_addr),sizeof(struct sockaddr))==-1)   
    {   
        fprintf(stderr,"Connect Error:%s\a\n",strerror(errno));   
        exit(1);   
    }   
    fprintf(stdout,"Connect Error:%s\a\n",strerror(errno));   
    /* 连接成功了 */   


    sendlen = strlen(msg);  
    if (send(sockfd, msg, sendlen, 0) != sendlen) {  
        fprintf(stdout,"Mismatch in number of sent bytes\n\n");  
        exit(1);
    }  
    fprintf(stdout,"send msg ok, %s,%d\n\n",msg,sendlen);

    if((nbytes=recv(sockfd,buffer,4096,0))==-1)   
    {   
        fprintf(stderr,"Read Error:%s\n",strerror(errno));   
        exit(1);   
    }   
    buffer[nbytes]='\0';   
    fprintf(stdout,"I have received:%s\n",buffer);   
    /* 结束通讯 */   
    close(sockfd);   
    exit(0);   
}  
